from BASIC.base import RequestBase


class url:
    """商城管理"""
    _URL_goods_list = "adminapi/shop/goods"
    _URL_goods_add = "adminapi/shop/goods/virtual"
    _URL_goods_edit = "adminapi/shop/goods/virtual/10000012"
    _URL_goods_price_down = "adminapi/shop/goods/sku/member_price"
    _URL_goods_price_up = "adminapi/shop/goods/sku/member_price"
    _URL_goods_delete = "adminapi/shop/goods/status"


class goods_guanli(RequestBase,url):
    def goods_list(self,goods_name):
        """商品查询"""
        data = {
            'page': '1',
            'limit': '10',
            'goods_name': goods_name,
            'goods_type': '',
            'brand_id': '',
            'label_ids': '',
            'start_sale_num': '',
            'end_sale_num': '',
            'start_price': '',
            'end_price': '',
            'status': '1',
            'order': '',
            'sort': '',
        }
        return self._get(self.goods_list.__name__,self._URL_goods_list,data)

    def goods_add(self,goods_name,price,stock):
        """商品添加"""
        data = {
            'goods_type': 'virtual',
            'goods_name': goods_name,
            'sub_title': '',
            'goods_image': 'upload/attachment/image/202412/30/173554280390b9bba5e5755efb9a146a3c7d1129ad_local.jpg',
            'goods_video': '',
            'goods_category': [
                2,
                1,
            ],
            'brand_id': '',
            'poster_id': '',
            'label_ids': [],
            'service_ids': [],
            'supplier_id': '',
            'status': '1',
            'sort': '',
            'addon_shop_supplier': [],
            'spec_type': 'single',
            'price': price,
            'market_price': '',
            'cost_price': '',
            'stock': stock,
            'sku_no': '',
            'unit': '',
            'virtual_sale_num': '',
            'member_discount': '',
            'is_limit': 0,
            'limit_type': 1,
            'max_buy': '',
            'min_buy': '',
            'attr_format': '[]',
            'attr_id': '',
            'goods_desc': '<p>自定义</p>',
            'skuCheckAll': False,
            'skuIsIndeterminate': False,
            'skuCheckedCities': [],
            'virtual_auto_delivery': '0',
            'virtual_receive_type': 'auto',
            'virtual_verify_type': '0',
            'virtual_indate': '0',
            'virtual_indate_day': '0',
            'goods_sku_data': {},
            'goods_spec_format': [],
        }
        return self._post(self.goods_add.__name__, self._URL_goods_add,data )

    def goods_edit(self,goods_id,goods_name):
        """商品编辑"""
        data = {
            'goods_id': goods_id,
            'goods_type': 'virtual',
            'goods_name': goods_name,
            'sub_title': '',
            'goods_image': 'upload/attachment/image/202412/30/173554280390b9bba5e5755efb9a146a3c7d1129ad_local.jpg',
            'goods_video': '',
            'goods_category': [
                2,
                1,
            ],
            'brand_id': '',
            'poster_id': '',
            'label_ids': [],
            'service_ids': [],
            'supplier_id': '',
            'status': '1',
            'sort': 0,
            'addon_shop_supplier': [],
            'spec_type': 'single',
            'price': '258.00',
            'market_price': '0.00',
            'cost_price': '0.00',
            'stock': 159,
            'sku_no': '',
            'unit': '件',
            'virtual_sale_num': 0,
            'member_discount': '',
            'is_limit': 0,
            'limit_type': 1,
            'max_buy': 0,
            'min_buy': 0,
            'attr_format': '[]',
            'attr_id': '',
            'goods_desc': '<p>自定义</p>',
            'skuCheckAll': False,
            'skuIsIndeterminate': False,
            'skuCheckedCities': [],
            'virtual_auto_delivery': '0',
            'virtual_receive_type': 'auto',
            'virtual_verify_type': '0',
            'virtual_indate': '0',
            'virtual_indate_day': '0',
            'goods_sku_data': {},
            'goods_spec_format': [],
            }
        return self._put(self.goods_edit.__name__, self._URL_goods_edit, data)

    def goods_price_down(self,goods_id):
        """添加会员折扣"""
        data = {
            'goods_id': goods_id,
            'member_discount': 'discount',
            'sku_list': [],
            }

        return self._put(self.goods_price_down.__name__, self._URL_goods_price_down, data)

    def goods_price_up(self,goods_id):
        """取消会员折扣"""
        data = {
            'goods_id': goods_id,
            'member_discount': '',
            'sku_list': [],
        }
        return self._put(self.goods_price_up.__name__, self._URL_goods_price_up, data)

    def goods_delete(self,goods_id):
        """商品下架"""
        data = {
             'goods_ids': goods_id,
             'status': 0,
        },
        return self._put(self.goods__delete.__name__, self._URL_goods_delete, data)

if __name__ == '__main__':
    obj = goods_guanli()
    obj.goods_price_down("10000031")